import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView,
    },
  ],
  scrollBehavior(to, from, savedPosition) {
    console.log(to, from, savedPosition)
    if (to.hash) {
      return {
        el: to.hash,
        // 在元素上 10 像素
        top: 0,
      }
    }
    // 始终在元素 #main 上方滚动 10px
    return {
      top: 0,
    }
  },
})

export default router
